
package com.example.demo.util;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class ServletUtil {

    /** 得到post的请求报文 */
    public static String getPostParams(HttpServletRequest req) {
        BufferedReader br;
        String params = null;
        try {
            br = new BufferedReader(new InputStreamReader(
                    (ServletInputStream) req.getInputStream(), "utf-8"));
            StringBuffer sb = new StringBuffer();
            String temp;
            while ((temp = br.readLine()) != null) {
                sb.append(temp);
            }
            br.close();
            params = sb.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return params;

    }
}
